<template>
    投资项目名称:
    <input type="text" v-model="Info.Iname">
    投资项目总额度:
    <input type="text" v-model="Info.Isumprice">
    <button @click="PageShow">查询</button>
<table border="1">
    <tr>
        <td>投资项目ID</td>
        <td>投资项目名称</td>
        <td>总额度</td>
        <td>已投金额</td>
        <td>剩余额度</td>
        <td>投资次数</td>
        <td>操作</td>
    </tr>
    <tr v-for="i in data">
        <td>{{ i.Iid }}</td>
        <td>{{ i.Iname }}</td>
        <td>{{ i.Isumprice.toFixed(2)}}CNY</td>
        <td>{{ i.Iyprice .toFixed(2)}}CNY</td>
        <td>{{ i.Isprice.toFixed(2) }}CNY</td>
        <td>{{ i.Inum }}</td>
        <td><a href="#" @click="DeleteById(i.Iid)">删除</a></td>
    </tr>
</table>
<a href="#" @click='PageChange("F")'>首页</a>
<a href="#" @click='PageChange("P")'>上一页</a>
<a href="#" @click='PageChange("N")'>下一页</a>
<a href="#" @click='PageChange("L")'>尾页</a>
一共有{{ PageInfo.ReCount }}条数据，一共有{{ PageInfo.PageCount }}页，当前第{{ PageInfo.PageIndex }}页，每页显示{{ PageInfo.PageSize }}条数据
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted}from 'vue'
const data:any=ref([
    {
        Iname:'',
        Isumprice:0,
        Iyprice:0,
        Isprice:0,
        Inum:0,
        Iid:0
    }
])
const PageInfo=ref({
    PageIndex:1,
    PageSize:2,
    ReCount:0,
    PageCount:0
})
const Info=ref({
    Iname:'',
    Isumprice:'',
})
onMounted(()=>{
    PageShow()
})
const PageShow=()=>{
    axios.get('https://localhost:44324/api/Lx/PageShow',
        {
            params:{
                PageIndex:PageInfo.value.PageIndex,
                PageSize:PageInfo.value.PageSize,
                Iname:Info.value.Iname,
                Isumprice:Info.value.Isumprice
            }
        }
    ).then(res=>{
        data.value=res.data.list
        PageInfo.value.ReCount=res.data.ReCount
        PageInfo.value.PageCount=res.data.PageCount
        console.log(res.data);
    }).catch(err=>{
        console.log(err);
    })
}
const PageChange=(msg:string)=>{
    if(msg=="F"){
        PageInfo.value.PageIndex=1
    }
    if(msg=="L"){
        PageInfo.value.PageIndex=PageInfo.value.PageCount
    }
    if(msg=="N"){
        if(PageInfo.value.PageIndex==PageInfo.value.PageCount){
            alert("已经是最后一页")
            return
        }
        PageInfo.value.PageIndex++
    }
    if(msg=="P"){
        if(PageInfo.value.PageIndex==1){
            alert("已经是第一页")
            return
        }
        PageInfo.value.PageIndex--
    }
    PageShow()
}
  const DeleteById=(Iid:number)=>{
    if(!confirm("确认删除嘛")){
        return
    }
    axios.get('https://localhost:44324/api/Lx/DeleteById',
        {
            params:{
                Iid:Iid
            }
        }
    ).then(res=>{
        if(res.data==-1){
            alert("该项目有客户正在投资，删除失败")
            return
        }else if(res.data>0){
            alert("删除成功")
            PageShow()
        }else{
            alert("删除失败")
        }
        console.log(res.data);
    }).catch(err=>{
        console.log(err);
    })
}

    


</script>